package org.karelun.gef.policies;

import org.eclipse.draw2d.Connection;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editpolicies.BendpointEditPolicy;
import org.eclipse.gef.requests.BendpointRequest;
import org.karelun.gef.commands.CreateBendpointCommand;
import org.karelun.gef.commands.DeleteBendpointCommand;
import org.karelun.gef.commands.MoveBendpointCommand;

public class CustomBendpointEditPolicy extends BendpointEditPolicy{

	//@Override
	protected Command getCreateBendpointCommand(BendpointRequest request) {
		Point point=request.getLocation();
		Connection connection = getConnection();
		connection.translateToRelative(point);
		
		CreateBendpointCommand command=new CreateBendpointCommand();
		command.setLocation(point);
		command.setConnection(getHost().getModel());
		command.setIndex(request.getIndex());
		return command;
	}

	//@Override
	protected Command getDeleteBendpointCommand(BendpointRequest request) {
		DeleteBendpointCommand command=new DeleteBendpointCommand();
		command.setConnectionModel(getHost().getModel());
		command.setIndex(request.getIndex());
		return command;
	}

	//@Override
	protected Command getMoveBendpointCommand(BendpointRequest request) {
		Point location=request.getLocation();
		getConnection().translateToRelative(location);
		
		MoveBendpointCommand command=new MoveBendpointCommand();
		command.setConnection(getHost().getModel());
		command.setIndex(request.getIndex());
		command.setNewLocation(location);
		return command;
	}

}
